package recievers

import "fmt"

type FanSpeed int

const (
	HIGH   FanSpeed = 3
	MEDIUM FanSpeed = 2
	LOW    FanSpeed = 1
	OFF    FanSpeed = 0
)

//记录上一个速度，可以让on和off的command undo
type Fan struct {
	speed    FanSpeed
	preSpeed FanSpeed
}

func (f *Fan) Shift(s FanSpeed) {
	f.preSpeed = f.speed
	var theSpeed FanSpeed
	if f.speed == OFF {
		theSpeed = 1
	} else {
		theSpeed = f.speed%3 + s
	}
	f.SpecifiedSpeed(theSpeed)
}

func (f *Fan) SpecifiedSpeed(s FanSpeed) {
	f.speed = s
	fmt.Printf("电扇%+v档\n", f.speed)
}

func (f *Fan) Off() {
	f.preSpeed = f.speed
	f.SpecifiedSpeed(OFF)
}

func (f *Fan) GetPreSpeed() FanSpeed {
	return f.preSpeed
}
